package com.dy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dy.pojo.dto.DyBlogByConDTO;
import com.dy.pojo.entity.DyBlogEntity;
import com.dy.pojo.vo.DyBlogVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)
 * @Date: 2021/6/8 14:56
 * @Version 1.0 (版本)
 */
@Mapper
@Repository
public interface DyBlogMapper extends BaseMapper<DyBlogEntity> {
    /**
     * 回收站查询
     * @return
     */
    @Select("select * from dy_blog where deleted=1")
    List<DyBlogEntity> recycleBlog();

    /**
     * 回收站删除
     */
    @Delete("delete from dy_blog where deleted=1")
    void taskDeleteBlog();

    /**
     * 删除标记更改
     * @param id id
     */
    @Update("update dy_blog set deleted=0 where id=#{id}")
    void updateDeleted(Long id);
    /**
     * 多条件查询
     * @param dyBlogByConDTO
     * @return List
     **/
    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_blog.title=#{title} and dy_type.name=#{typeName} and dy_blog.recommend=#{recommend} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon1(DyBlogByConDTO dyBlogByConDTO);

    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_blog.title=#{title} and dy_type.name=#{typeName} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon2(DyBlogByConDTO dyBlogByConDTO);

    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_blog.title=#{title} and dy_blog.recommend=#{recommend} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon3(DyBlogByConDTO dyBlogByConDTO);

    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_type.name=#{typeName} and dy_blog.recommend=#{recommend} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon4(DyBlogByConDTO dyBlogByConDTO);

    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_blog.title=#{title} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon5(DyBlogByConDTO dyBlogByConDTO);

    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_type.name=#{typeName} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon6(DyBlogByConDTO dyBlogByConDTO);

    @Select("select dy_blog.published,dy_blog.id,dy_blog.title,dy_type.name,dy_blog.recommend,dy_blog.createTime,dy_blog.updateTime from dy_blog inner join dy_type on dy_blog.type_code=dy_type.code where dy_blog.recommend=#{recommend} and dy_blog.deleted=0")
    List<DyBlogVO> selectBlogByCon7(DyBlogByConDTO dyBlogByConDTO);
    /**
     * 取数量最多前六个的type_code
     * @return
     **/
    @Select("select type_code from dy_blog group by type_code order by count(type_code) desc limit 6")
    List<String> queryBy6();
    /**
     * 查询日期最新的前四条数据
     * @return
     **/
    @Select("select * from dy_blog order by updateTime desc limit 4")
    List<DyBlogEntity> selectNewstBlog();
}
